<template>
	<view class="content">
		<view class="pageHeader">
			{{title}}
			<a class="generalBack" @click="backpage()" hover-class="none">
				<image src="/static/b-1.png" style="width: 18upx;height: 30upx;"></image>
			</a>
		</view>
		<view style="z-index:1;padding:180upx 0upx 22upx;">
			<scroll-view scroll-y="true" class="scroll-Y" >
				<view v-if="powerlist.length<=0" class="empty">
					<image src="/static/empty.png" mode="widthFix"></image>
					<view class="empty-tips">
						暂无文件~
					</view>
				</view>
				<view style="padding: 20upx 30upx;display: flex;flex-wrap: wrap;" class="hot-goodbox">
					<view class="gooditem" v-for="(item,index) in powerlist" :key="index">
						<view>
							<image :src="item.images" style="height: 288upx;width:100%;border-radius: 20upx 20upx 0 0;"></image>
						</view>
						<view style="padding: 14upx;">
							<view class="goodtitle">{{item.title}}</view>
							<view style="margin: 10upx 0;" class="flex aic jsb">
								<text class="powerprice">￥{{item.price}}</text>
								<view class="rebtn" @click="powerbuy(item)">购买</view>
							</view>
						</view>
					</view>
				</view>
				<view class="loading">{{ loadingText }}</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	import postAjax from '../../API/postAjax.js';
	export default {
		data() {
			return {
				userToken: '', // token
				title:'',
				powerlist:[
					
				],
				page : 1,
				type:0,
				loadingText: '加载中...'
			};
		},

		onLoad(options) {
			let that = this;
			//0经销商 1 代理商 2 合伙人
			if(options.type==0&&options.state==0){
				that.title = '经销商置权'
				that.type= 5
			}else if(options.type==0&&options.state==1){
				that.title = '经销商提货区'
				that.type= 6
			}else if(options.type==1&&options.state==0){
				that.title = '代理商置权'
				that.type= 7
			}else if(options.type==1&&options.state==1){
				that.title = '代理商提货区'
				that.type= 8
			}else if(options.type==2&&options.state==0){
				that.title = '合伙人置权'
				that.type= 9
			}else if(options.type==2&&options.state==1){
				that.title = '合伙人提货区'
				that.type= 10
			}
			that.get_power_goods()
		},
		methods: {
			// 返回上一页
			backpage() {
				uni.navigateBack({
					delta: 1
				})
			},
			powerbuy(i){
				uni.navigateTo({
					url:'busconfirm?type='+this.type+'&buynum=1&item='+JSON.stringify(i)
				})
			},
			onReachBottom:function(){
				this.get_power_goods();
			},
			// type 1：普通商品 2：抢购3：公益仓，4：国际保税区 5:经销商置权 6经销商提货区 7代理置权8代理提货 9合伙人置权 10合伙人提货 11vs购买置权套装
			get_power_goods() {
				let that = this
				uni.showLoading()
				let postdata ={
					m:0,
					n:8,
					type:that.type
				}
				// 列表
				let balanceList = []
				postAjax('Promotebusiness/promotebusinesslist',postdata,function(data){
					console.log(data.data)
					if(data.code==0){
						balanceList = data.data
						if (balanceList.length > 0) {
							that.powerlist = that.powerlist.concat(balanceList);
										
							that.page++; //每触底一次 page +1
						} else {
							that.loadingText = '已加载全部';
						}
						if(that.powerlist.length<10){
							that.loadingText = ''
						}
						uni.hideLoading()
					}else{
						that.powerlist = that.powerlist.concat(balanceList)
					}
				})
			},
		}
	};
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #f9f9f9;
	}
	.flex-1 {
		flex: 1
	}
	.powerprice{font-size: 28upx;color: #EC6104;}
	.gooditem {
		background-color: #fff;
		color: #fff;
		font-size: 28upx;
		border-radius: 20upx;
		width: 48%;
		margin-bottom: 20upx;
	}
	
	.hot-goodbox>.gooditem:nth-child(2n+2) {
		margin-left: 4%;
	}
	
	.goodtitle {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		color: #333;
	}
	
	.pageHeader {
		position: fixed;
		top:0;left: 0;
		z-index: 10;
		width: 100%;
		height: 120upx;
		background-color: #1d84e8;
		line-height: 120upx;
		text-align: center;
		font-size: 36upx;
		color: #fff;
		padding-top: 40upx;
		display: block;
	}

	.generalBack {
		position: absolute;
		top: 40upx;
		left: 30upx;
		display: block;
	}

	
	.rebtn {
		display: inline-block;
		font-size: 30upx;
		border-radius: 6upx;
		width: 120upx;
		height: 58upx;
		line-height: 58upx;
		text-align: center;
		background-color: #1D84E8;
		color: #fff;
		font-size: 26upx;
	}

	.rebtn::after {
		border: none;
	}
	.loading {
		text-align: center;
		line-height: 50px;
		font-size: 30upx;
		color: #666;
	}
	.empty {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100vh;
		padding-bottom: 100upx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		background: #fff;
	
	}
	
	.empty image {
		width:240upx;
		margin-bottom: 30upx;
	}
	.empty-tips {
		display: flex;
		font-size: 30upx;
		color: #666;
	
	}
</style>
